import React, { useEffect, Fragment } from 'react';
import { Form, Input, Icon, Select } from 'antd';
import { FormContainer, SearchInput } from '@/components/UserForm';
import { searchCandidate } from '@/services/myRecruit/interview';
import LinkTo from '@/components/LinkTo';
import styles from '../TerviewList.less';

const InfoFrom = ({ form, onCandidateSearch, resourceRelation, dictList, candidate, pathname }) => {
    const { getFieldDecorator } = form;
    const { Option } = Select;
    const candidateSearch = (id, option) => {
        if (id) {
            onCandidateSearch(option.props.code);
        }
    };
    const { disable = '' } = dictList;
    useEffect(() => {}, []);
    return (
        <Fragment>
            <h3 className="vv-from-title">应聘信息</h3>
            <FormContainer>
                <Form.Item label="候选人姓名">
                    <div style={{ display: 'flex', position: 'relative' }}>
                        <div style={{ width: '100%' }}>
                            {getFieldDecorator('talentName', {
                                rules: [
                                    {
                                        required: true,
                                        message: '请输入候选人姓名'
                                    }
                                ]
                            })(
                                <SearchInput
                                    params={{
                                        searchStage: 'interview'
                                    }}
                                    getData={params =>
                                        searchCandidate(params).then(res => {
                                            if (res && res.code === 10000) {
                                                return res.data || [];
                                            }
                                            return [];
                                        })
                                    }
                                    selectProps={{
                                        placeholder: '请输入候选人姓名',
                                        allowClear: true,
                                        disabled: disable
                                    }}
                                    fieldsName={{
                                        value: 'talentId',
                                        title: 'talentName',
                                        extraParams: 'candidateName',
                                        isInterview: true
                                    }}
                                    onChange={(v, option) => {
                                        candidateSearch(v, option);
                                    }}
                                />
                            )}
                        </div>
                        <LinkTo
                            className={styles.detail}
                            to={
                                pathname === 'admineditinterview' || pathname === 'adminseeinterview'
                                    ? '/office/personnelManagement/recruit/candidate/detail'
                                    : '/personal/portal/recruit/candidate/detail'
                            }
                            query={{
                                candidateCode: candidate.candidateCode,
                                isApplyOffer: candidate.isOffer || false,
                                isInterview: candidate.isInterview || false
                            }}
                            disabled={candidate.length === 0}
                            target="_blank"
                        >
                            详情
                        </LinkTo>
                    </div>
                </Form.Item>
                <Form.Item label="手机号">
                    {getFieldDecorator(
                        'talentPhone',
                        {}
                    )(
                        <Input
                            disabled
                            placeholder="请填入手机号"
                            addonBefore={getFieldDecorator(
                                'talentAreaCode',
                                {}
                            )(
                                <Select placeholder="区号" place style={{ width: 80 }} disabled>
                                    <Option value="86">+86</Option>
                                    <Option value="65">+65</Option>
                                </Select>
                            )}
                        />
                    )}
                </Form.Item>
                <Form.Item label="应聘部门">
                    {getFieldDecorator('departmentName', {
                        rules: [
                            {
                                required: true,
                                message: '请选择应聘部门'
                            }
                        ],
                        initialValue: ''
                    })(<Input disabled />)}
                </Form.Item>
                <Form.Item label="项目组">{getFieldDecorator('projectGroup', {})(<Input disabled />)}</Form.Item>
                <Form.Item label="应聘职位">
                    {getFieldDecorator('recruitPost', {
                        rules: [
                            {
                                required: true,
                                message: '请选择应聘职位'
                            }
                        ],
                        initialValue: ''
                    })(<Input disabled />)}
                </Form.Item>
                <Form.Item label="职级">{getFieldDecorator('postGradeCode', {})(<Input disabled />)}</Form.Item>

                {resourceRelation && resourceRelation.length ? (
                    <Form.Item label="附件" vvspan={24} labelCol={{ md: 4 }} wrapperCol={{ md: 20 }}>
                        {resourceRelation.map(item => (
                            <div key={item.keyName}>
                                <Icon type="paper-clip" />
                                <a
                                    // eslint-disable-next-line react/jsx-no-target-blank
                                    target="_blank"
                                    style={{ marginLeft: 8 }}
                                    href={item.url}
                                    download
                                >
                                    {item.originName}
                                </a>
                            </div>
                        ))}
                    </Form.Item>
                ) : null}
            </FormContainer>
        </Fragment>
    );
};
export default InfoFrom;
